package us.versus.them.hmap;

import flash.display.DisplayObject;
import flash.display.Loader;
import flash.events.Event;
import flash.net.URLRequest;

class UriLoader {
	var onComplete : String -> DisplayObject -> Void;
	var uri : String;

	public function new( uri : String, ?onComplete_ ) {
		this.setUri( uri );
		if ( null != onComplete_ ) {
			this.onComplete = onComplete_;
		}
	}

	public function getUri() : String {
		return this.uri;
	}

	public function setUri( uri : String ) {
		this.uri = uri;
	}

	public function load( onComplete : String -> DisplayObject -> Void ) {
		var loader:Loader = new Loader();
		this.onComplete = onComplete;
		loader.contentLoaderInfo.addEventListener( Event.COMPLETE, onLoad );
		loader.load( new URLRequest( this.getUri() ) );
	}
	
	public function onLoad( event : Event ) : Void {
		this.onComplete( uri, event.currentTarget.content );
	}
}
